package com.koocloud.electroplatemanage.controller;

import com.koocloud.electroplatemanage.common.pojo.ResponseTemplate;
import com.koocloud.electroplatemanage.pojo.AssignJobVo;
import com.koocloud.electroplatemanage.pojo.BtProductPlanUrgent;
import com.koocloud.electroplatemanage.service.AssignJobService;
import com.koocloud.electroplatemanage.service.ProductPlanUrgentService;
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @program: Information_platform
 * @description: 生产计划加急控制层
 * @author: 2019110501
 * @create: 2020-11-04 10:16
 */
@RestController
@RequestMapping("/productPlanUrgent")
public class BtProductPlanUrgentController {
    static Logger log = Logger.getLogger("productPlanUrgent");
    @Autowired
    ProductPlanUrgentService productPlanUrgent;


    /**
     * 新增 加急表 成功时，将主表的数据状态置为1（0删除1.未删除2.加急状态），设置生产计划的状态为0  order 从1开始递增
     * @param workOrderNumber 生产计划的id
     * @return
     */
    @RequestMapping(value = "/insert", method = RequestMethod.POST, name = "新增一条数据")
    public ResponseTemplate insert(String workOrderNumber) {
        BtProductPlanUrgent btProductPlanUrgent = new BtProductPlanUrgent();
        btProductPlanUrgent.setProductionPlanId(workOrderNumber);
        //插入一条记录
        return productPlanUrgent.insert(btProductPlanUrgent);
    }


    /**
     * 生产计划加急列表的全查询
     * @param page
     * @param limit
     * @return
     */
        @RequestMapping(value = "/selectAllData", method = RequestMethod.POST, name = "生产计划加急列表的全查询")
    public ResponseTemplate selectAllData(String page, String limit) {
        //分页参数为空则赋值0
        if (!StringUtils.isNotEmpty(page)) {
            page = "0";
        }
        if (!StringUtils.isNotEmpty(limit)) {
            limit = "0";
        }
        //查询所有记录 分页
        return productPlanUrgent.selectAllData(page,limit);
    }

    /**
     * 根据id查询加急单的order
     * @param urgentId
     * @return
     */
    @RequestMapping(value = "/selectOrderById", method = RequestMethod.POST, name = "根据id查询加急单的order")
    public ResponseTemplate selectOrderById(String urgentId) {
        //根据id查询加急单的order
        return productPlanUrgent.selectOrderById(urgentId);
    }


    /**
     * 修改加急单的order
     * @param urgentId
     * @param order
     * @return
     */
    @RequestMapping(value = "/update", method = RequestMethod.POST, name = "修改加急单的order")
    public ResponseTemplate update(@RequestParam(name="urgentId") String urgentId, @RequestParam(name="order") String order) {
        //修改加急单的order
        return productPlanUrgent.update(urgentId,order);
    }
    /**
     * 二次加急
     * @param urgentId
     * @param order
     * @return
     */
    @RequestMapping(value = "/expedited", method = RequestMethod.POST, name = "二次加急")
    public ResponseTemplate expedited(@RequestParam(name = "urgentId") String urgentId,@RequestParam(name="order") String order){
        return productPlanUrgent.expedited(urgentId,(1000000000+Integer.parseInt(order)+""));
    }

    /**
     *  取消加急单 物理删除加急单
     * @param urgentId
     * @param
     * @return
     */
    @RequestMapping(value = "/delete", method = RequestMethod.POST, name = "物理删除加急单")
    public ResponseTemplate delete(@RequestParam(name="urgentId") String urgentId) {
        //物理删除加急单
        return productPlanUrgent.delete(urgentId);
    }
    /**
     *  取消二次加急单
     * @param urgentId
     * @param
     * @return
     */
    @RequestMapping(value = "/deleteExpedited", method = RequestMethod.POST, name = "物理删除加急单")
    public ResponseTemplate deleteExpedited(@RequestParam(name="urgentId") String urgentId) {
        //物理删除加急单
        return productPlanUrgent.deleteExpedited(urgentId);
    }

}
